<template>
	<view>
		<nav-bar title="修改密码" :border="false" />
		<view class="padding-lr margin-tb bgWhite">
			<u--form labelPosition="left" :model="formData" ref="formData" labelWidth="90">
				<u-form-item borderBottom label="原密码">
					<u-input v-model="formData.password" placeholder="请输入原密码" border="none" :password="showConfirmPass">
						<template #suffix>
							<u-icon :name="showConfirmPass?'eye-fill':'eye-off'" color="#999"
								@click="showConfirmPass=!showConfirmPass" />
						</template>
					</u-input>
				</u-form-item>
				<u-form-item borderBottom label="新密码">
					<u-input v-model="formData.newPassword" placeholder="请输入新密码" border="none" :password="showNewPassword">
						<template #suffix>
							<u-icon :name="showNewPassword?'eye-fill':'eye-off'" color="#999"
								@click="showNewPassword=!showNewPassword" />
						</template>
					</u-input>
				</u-form-item>
				<u-form-item borderBottom label="密码重复">
					<u-input v-model="formData.newPassword2" placeholder="新密码重复" border="none" :password="showNewPassword2"><template #suffix>
							<u-icon :name="showNewPassword2?'eye-fill':'eye-off'" color="#999"
								@click="showNewPassword2=!showNewPassword2" />
						</template>
					</u-input>
				</u-form-item>
				<u-gap height="20" />
				<u-button type="primary" @click="submiForm" :custom-style="{width:'100%'}">修改</u-button>
				<u-gap height="20" />
				</u-form-item>
			</u--form>
		</view>
	</view>
</template>

<script>
	import {
		resetPassApi
	} from '@/common/api/user.js'
	export default {
		data() {
			return {
				userType: this.$store.state.vuex_userType, //用户类型 1 用户 ，2 医生，3 管理员
				userInfo: this.$store.state.vuex_user, //用户信息
				formData: {
					password:'',
					newPassword:'',
					showNewPassword2:''
					
				},
				showConfirmPass:true,//密码显示隐藏
				showNewPassword:true,//确认密码显示隐藏
				showNewPassword2:true,//确认密码显示隐藏
				rule: [{
						name: "password",
						checkType: "notnull",
						errorMsg: "请输入原密码"
					},
					{
						name: "newPassword",
						checkType: "notnull",
						errorMsg: "请输入新密码"
					},
					{
						name: "newPassword2",
						checkType: "same",
						// checkRule:this.formData.mima,
						errorMsg: "请与密码保持一致"
					},
				],
			}
		},
		methods: {
			async submiForm() {
				
				let that = this
				that.rule[2].checkRule = that.formData.newPassword
				var checkRes = that.$validateCheck.check(that.formData, that.rule)
				that.formData.id = that.userInfo.id
				that.formData.mima = that.formData.password
				if (checkRes) {
					const res = await resetPassApi(this.formData, this.userType)
					if (res.code==='0') {
						uni.showToast({
							title: "修改成功，重新登录",
							icon: "none",
						});
						setTimeout(() => {
							uni.removeStorageSync('lifeData') //移除token 和用户信息
							that.$uniRouter.navigateTo({
								url: '/pages/login/login'
							})
						}, 2000)

					}
				}else{
					uni.showToast({
						title: that.$validateCheck.error,
						icon: "none"
					});
				}
			}
		}
	}
</script>

<style>
</style>